﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Data;

namespace DataAccess {
    /// <summary>
    /// Class for retreiving user data
    /// </summary>
    public class CheckUser_Access {
        /// <summary>
        /// Check_s the user.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns>
        /// true if the user data match, false otherwise
        /// </returns>
        public bool Check_User(CheckUser_Data obj) {
            string role = String.Empty;
            CreateConnection objcon = new CreateConnection();
            try {
                string query = "SELECT role FROM Users" +
                " WHERE (username = '" + obj.UserName + "')";
                DataTable dt = objcon.CreateDataTable(query);
                role = dt.Rows[0]["role"].ToString();
            } catch (Exception e) {
                Console.Write("Err msg:" + e.Message);
            }
            if (role.Equals("Admin"))
                return true;
            else
                return false;
        }
    }


    /// <summary>
    /// Class for retreiving admin data
    /// </summary>
    public class CheckAdmin_Access {
        /// <summary>
        /// Check_s the user.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns>
        /// true if the user data match, false otherwise
        /// </returns>
        public bool Check_Admin(CheckAdmin_Data obj) {
            string is_admin = String.Empty;
            CreateConnection objcon = new CreateConnection();
            try {
                string query = "SELECT is_admin FROM Users" +
                " WHERE (username = '" + obj.UserName + "')";
                DataTable dt = objcon.CreateDataTable(query);
                is_admin = dt.Rows[0]["is_admin"].ToString();
            } catch (Exception e) {
                Console.Write("Err msg:" + e.Message);
            }
            if (is_admin.Equals("Admin"))
                return true;
            else
                return false;
        }
    }
}
